import config from '../../package.json'

class Storages {
  constructor() {
  }
  public beforeKey = JSON.stringify(config.name).replace(/\"/g,'')
  public afterKey = JSON.stringify(config.version).replace(/\"/g,'')
  setItem(key:string,value: any) {

    if (value instanceof Object) {
      value = JSON.stringify(value)
    }
    localStorage.setItem(`${this.beforeKey}_${key}_${this.afterKey}`,value)
  }
  getItem(key: string): any {
    let data = localStorage.getItem(`${this.beforeKey}_${key}_${this.afterKey}`)
    return data
  }
  removeItem(key:string) {
    localStorage.removeItem(`${this.beforeKey}_${key}_${this.afterKey}`)
  }
  clear() {
    localStorage.clear()
  }
}

let storage = new Storages()

export default storage